package com.whub507.msgmanager.controller;

import com.whub507.msgmanager.common.Field;
import com.whub507.msgmanager.common.ResResult;
import com.whub507.msgmanager.common.ZWWW;
import com.whub507.msgmanager.config.ZWWWConfig;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/Zwww")
@Api(tags = "政务外网信息管理接口")
public class ZwwwController {
    @Resource
    ZWWWConfig zwwwConfig;

    @GetMapping("/getZwww")
    @ApiOperation(value = "获取政务外网访问信息")
    public ResResult<ZWWW> getZwww(){
        List<Field> fields = new ArrayList<>();
        fields.add(new Field("url", "政务外网接口访问网址"));
        fields.add(new Field("name", "政务外网接口访问账户"));
        fields.add(new Field("password", "政务外网接口访问密钥"));
        return ResResult.ok(zwwwConfig.getZwww(), fields);
    }

    @PostMapping("/editZwww")
    @ApiOperation(value = "修改政务外网访问信息")
    public ResResult<Boolean> editZwww(ZWWW zwww){
        zwwwConfig.setZwww(zwww);
        return ResResult.ok(Boolean.TRUE, "修改成功");
    }
}
